package com.itheima.demo;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @program: jmm
 * @description:
 * @author: zhanghz001
 * @create: 2020-12-30 10:44
 **/
public class AtomicInteger1 {
    public static void main(String[] args) {
        AtomicInteger integer = new AtomicInteger(0);
        boolean b;
        do {
            int expectedValue = integer.get();
            int newValue = expectedValue + 1;
            b = integer.compareAndSet(expectedValue, newValue);
        } while (!b);
        System.out.println(integer.get());
    }
}
